package com.duowei.kitchenshow;

import android.app.FragmentManager;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckedTextView;

import com.duowei.kitchenshow.fragment.setting.BaseSettingFragment;
import com.duowei.kitchenshow.fragment.setting.OtherSettingFragment;
import com.duowei.kitchenshow.fragment.PrintSettingFragment;

public class SettingActivity extends AppCompatActivity implements View.OnClickListener {

    private CheckedTextView mTv1;
    private CheckedTextView mTv2;
    private CheckedTextView mTv3;
    private View mView1;
    private View mView2;
    private View mView3;
    private FragmentManager mFm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        mTv1 = findViewById(R.id.tv1);
        mTv1.setOnClickListener(this);
        mTv2 = findViewById(R.id.tv2);
        mTv2.setOnClickListener(this);
        mTv3 = findViewById(R.id.tv3);
        mTv3.setOnClickListener(this);
        mView1 = findViewById(R.id.view1);
        mView2 = findViewById(R.id.view2);
        mView3 = findViewById(R.id.view3);
        mFm = getFragmentManager();
        mFm.beginTransaction().replace(R.id.frame,new BaseSettingFragment()).commit();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.options_menu,menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if(item.getItemId()==R.id.menu_exit){
            Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);
            finish();
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onClick(View v) {
        if(v.getId()==R.id.tv1){
            mTv1.setChecked(true);
            mTv2.setChecked(false);
            mTv3.setChecked(false);
            mView1.setVisibility(View.VISIBLE);
            mView2.setVisibility(View.INVISIBLE);
            mView3.setVisibility(View.INVISIBLE);
            mFm.beginTransaction().replace(R.id.frame,new BaseSettingFragment()).commit();
        }else if(v.getId()==R.id.tv2){
            mTv2.setChecked(true);
            mTv1.setChecked(false);
            mTv3.setChecked(false);
            mView2.setVisibility(View.VISIBLE);
            mView1.setVisibility(View.INVISIBLE);
            mView3.setVisibility(View.INVISIBLE);
            mFm.beginTransaction().replace(R.id.frame,new PrintSettingFragment()).commit();
        }else if(v.getId()==R.id.tv3){
            mTv3.setChecked(true);
            mTv1.setChecked(false);
            mTv2.setChecked(false);
            mView3.setVisibility(View.VISIBLE);
            mView2.setVisibility(View.INVISIBLE);
            mView1.setVisibility(View.INVISIBLE);
            mFm.beginTransaction().replace(R.id.frame,new OtherSettingFragment()).commit();
        }
    }
}
